import { combineReducers } from 'redux';
import byId, * as fromById from './byId';
import createList, * as fromList from './createList';

const listByFilter = combineReducers({
  'all': createList('all'),
  'uncompleted': createList('uncompleted'),
  'completed': createList('completed')
});


const todos = combineReducers({
  byId,
  listByFilter
});

export default todos;

export const getVisibleTodos = (state, filter) => {
  const ids = fromList.getIds(state.listByFilter[filter]);
  return ids.map((id) => fromById.getTodo(state.byId, id));
};

export const getIsFetching = (state, filter) => fromList.getIsFetching(state.listByFilter[filter]);


export const getErrorMessage = (state, filter) =>
fromList.getErrorMessage(state.listByFilter[filter]);